package com.china08.yxyapi.util;

import org.apache.commons.lang3.BooleanUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@EnableScheduling
public class YxyScheduleRunnableUtil {
    private static final Logger LOGGER = LoggerFactory.getLogger(YxyScheduleRunnableUtil.class);

    public static final String YXY_SCHEDULE_RUNNABLE = "YXY_SCHEDULE_RUNNABLE";

    public static boolean checkRunnable() {
        String envYxyScheduleRunnable = System.getenv(YXY_SCHEDULE_RUNNABLE);
        boolean runnable = BooleanUtils.toBoolean(envYxyScheduleRunnable);
        LOGGER.info("CheckEnv:YXY_SCHEDULE_RUNNABLE:" + runnable);
        return runnable;
    }

    @Scheduled(cron = "0 */1 * * * *")
    public void process() {
        LOGGER.info("CheckEnv:YXY_SCHEDULE_RUNNABLE:===========================");
        YxyScheduleRunnableUtil.checkRunnable();
        LOGGER.info("CheckEnv:YXY_SCHEDULE_RUNNABLE:===========================");
    }
}
